#!/bin/sh
SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)

sudo apt update
sudo apt install docker.io
sudo apt install docker-compose
sudo apt install certbot

git submodule init
git submodule update

cp  -r trojan-override/* trojan/


echo 'input the domain:'
read domain

echo 'input trojan password:'
read pwd

if [ ! $pwd ]; then
        pwd=`cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c9`
fi

echo $pwd $domain

sudo certbot certonly --standalone -d $domain
sudo cat /etc/letsencrypt/live/*/fullchain.pem > cert/fullchain.pem
sudo cat /etc/letsencrypt/live/*/privkey.pem > cert/privkey.pem
sudo echo "0 0 1 */2 0 /bin/sh $SHELL_FOLDER/renew_cert.sh" >> /var/spool/cron/root

#开启tcp拥塞控制bbr
sudo echo net.core.default_qdisc=fq >> /etc/sysctl.conf
sudo echo net.ipv4.tcp_congestion_control=bbr >> /etc/sysctl.conf
sudo sysctl -p

password=$pwd domain=$domain docker-compose build
sudo docker-compose up -d
